@if($purchase->order_contract->isNotEmpty())
<div class="box box-solid no-margin box-show">
    <div class="box-body">
        <h4>合同文件</h4>
        <div class="box-body table-responsive no-padding">
            <table class="table">
                <thead>
                <tr>
                    <th style="width: 25%">名称</th>
                    <th style="width: 25%">类型</th>
                    <th style="width: 25%">生成时间</th>
                    <th style="width: 25%">操作</th>
                </tr>
                </thead>
                <tbody>
                    @foreach($purchase->order_contract as $item)
                        <tr>
                            <td>{{ \App\Models\Purchase\PurchaseOrderContract::fileName($item->purchase_no,$item->type) }}</td>
                            <td>{{ \App\Models\Purchase\PurchaseOrderContract::$_type[$item->type] }}</td>
                            <td>{{ $item->created_at }}</td>
                            <td>
                                <button class="btn btn-xs btn-default contract_export" data-id="{{ $item->id }}"><i class="fa fa-download"></i> 下载</button>
                                <button class="btn btn-xs btn-danger contract_delete" data-id="{{ $item->id }}"><i class="fa fa-remove"></i> 删除</button>
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    </div>
</div>
<script language="JavaScript" type="text/javascript">
    $(function () {
        $('.contract_export').on('click', function (e) {
            e.preventDefault();
            var id = $(this).data('id');
            window.location.href = '/xqc/purchase/order-modal?action=exportPurContract&param=' + id;
        });

        $('.contract_delete').on('click', function(e) {
            e.preventDefault();
            var id = $(this).data('id');
            swal({
                title: "确定删除？",
                text : "确定要删除合同文件吗？",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确认",
                showLoaderOnConfirm: true,
                cancelButtonText: "取消",
                preConfirm: function() {
                    return new Promise(function(resolve) {
                        $.ajax({
                            method: 'post',
                            url: '/xqc/purchase/order-ajax',
                            data: {
                                _token: "{{ csrf_token() }}",
                                action: 'delPurContract',
                                param: id
                            },
                            success: function (data) {
                                resolve(data);
                            }
                        });
                    });
                }
            }).then(function(result) {
                var data = result.value;
                if (typeof data === 'object') {
                    if (data.status) {
                        toastr.success('删除成功 !');
                        $.pjax.reload('#order-edit-form');
                    } else {
                        swal(data.message, '', 'error');
                    }
                }
            });
        });
    });
</script>
@endif
